<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" v-model="isAll" type="checkbox" />
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      v-model.trim="Todolist"
      placeholder="输入任务名称-回车确认"
      @keyup.enter="addTodo"
      autofocus
    />
  </header>
</template>

<script>
export default {
  data() {
    return {
      Todolist: "",
    };
  },
  props: {
    list: {
      type: Array,
      required: true,
    },
  },
  computed: {
    isAll: {
      get() {
        return this.list.every((item) => item.isDone);
      },
      set(val) {
        console.log(val);
        this.$emit("chnageIsAll", val);
      },
    },
  },
  methods: {
    // Isall(isallchek) {
    //   console.log(isallchek);
    // },
    addTodo() {
      // 按下回车把要添加的数据传递给父组件
      this.$emit("addTodoList", this.Todolist);
      // 清除input
      this.Todolist = "";
    },
  },
};
</script>